package dltec.demo;

import java.util.Arrays;

public class demo01 {

	public static void main(String[] args) {
		/**
		 * 引用之间互相比较需要实现Comparable接口（自然比较，由小到大顺序  “内部比较器”
		 * 自定义比较规则使用：Comparator “外部比较器”
		 * <T>:指定比较的是哪一个类型）
		 *
		 * Comparable和Comparator接口的区别：
		 * 		Comparable接口更通用，java类实现该接口需要重写compareTo方法，作为通用比较规则，
		 * 		Comparator接口更适合特殊场景，针对某个特定实例，进行特性排序规则时，采用匿名内部类方式，
		 * 		实现该接口，重写compare方法。
		 */
		String[] strs = {"EE","FF","AA","DD","BB","CC","GG"};
		
		//排序
		Arrays.sort(strs);
		
		System.out.println(Arrays.toString(strs));
				
		//创建两个对象
		Goods g1 = new Goods("华为",4999);
		Goods g2 = new Goods("苹果",4999);
		Goods g3 = new Goods("opple",3999);
		Goods g4 = new Goods("vivo",5299);
		Goods g5 = new Goods("小米",2999);
		Goods g6 = new Goods("三星",4999);
		
		Goods[] goods = {g1,g2,g3,g4,g5,g6};
		
		Arrays.sort(goods);
		System.out.println(Arrays.toString(goods));

	}

}
